package com.ln.store.web.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ln.store.domain.Category;
import com.ln.store.domain.Product;
import com.ln.store.service.CategoryService;
import com.ln.store.service.ProductService;
import com.ln.store.service.Impl.CategoryServiceImpl;
import com.ln.store.service.Impl.ProductServiceImpl;
import com.ln.store.web.base.BaseServlet;

/**
 * Servlet implementation class IndexServlet
 */
public class IndexServlet extends BaseServlet {
		
		/**
		 * 首页
		 * @param request
		 * @param response
		 * @return
		 * @throws SQLException 
		 */
		public String execute(HttpServletRequest request,HttpServletResponse response) throws SQLException {
			
			//调用业务层查询最新商品，查询最热商品，返回2个集合
			ProductService service = new ProductServiceImpl();
			List<Product> list01 = service.findNews();
			List<Product> list02 = service.findHots();
			//System.out.println(list01);
			//将2个集合放入到request
			request.setAttribute("news", list01);
			request.setAttribute("hots", list02);
			//转发到真实的首页
			return "/jsp/index.jsp";
//			try {
//				//调用业务层：获取全部分类信息，返回集合
//				CategoryService service = new CategoryServiceImpl();
//				List<Category> list = service.getAllCats();
//				//将返回的集合放入request
//				request.setAttribute("allCats", list);
//				//转发到真实的首页
//				return "/jsp/index.jsp";
//			} catch (SQLException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//				return null;
//			}
		}
}
